<div class="row">	
	<!-- Add -->
	<div id="addModal" class="reveal-modal medium" data-reveal>
		<p class="p-modal">Tambah Data Master Tholabah <?php foreach ($list_jp as $row_jp) {echo $jp = $row_jp->j_pendidikan;$idjp = $row_jp->id_m_j_pendidikan;}?></p>
		<div class="isi-modal">
			<?php 
				echo form_open('m_tholabah/save', array('id' => 'SaveTholabah')); 
			?>
			
			<div class="row">
				<div class="col-md-6">
					<input type="text" name="nama_lengkap" class="form-control form-elba input-sm clearable" placeholder="Nama Lengkap"/><br/>							
					<input type="hidden" id="id_m_j_pendidikan" name="id_m_j_pendidikan" value="<?php echo $idjp;?>"/>						
					<div class="radioForm">
					<label class="radio-inline" id="radioCustom">
						<input type="radio" name="jk" value="Laki-laki"> <labelnya>Laki-laki</labelnya>
					</label>
					<label class="radio-inline" id="radioCustom">
						<input type="radio" name="jk" value="Perempuan"> <labelnya>Perempuan</labelnya>
					</label>
					</div><br/>
					<div class="input-group">
						<input type="text" name="tmp_lahir" class="form-control form-elba input-sm clearable" placeholder="Tempat lahir">
						<span class="input-group-addon group-addon-elba-tengah group-addon-elba b-hijau-muda ">pada tanggal</span>
						<input type="text" id="tgl1" name="tgl_lahir" class="form-control form-elba input-sm inputmask-cal clearable" placeholder="Tanggal lahir">
					</div><br/>
					<div class="input-group">
						<span class="input-group-addon group-addon-elba b-hijau-muda ">Anak ke</span>
						<input type="text" name="anak_ke" class="form-control form-elba input-sm clearable" placeholder="#">
						<span class="input-group-addon group-addon-elba-tengah group-addon-elba b-hijau-muda ">dari</span>
						<input type="text" name="jml_bersaudara" class="form-control form-elba input-sm clearable" placeholder="#">
						<span class="input-group-addon group-addon-elba b-hijau-muda ">bersaudara</span>
					</div><br/>
					<div class="input-group">
					<span class="input-group-addon group-addon-elba b-hijau-muda ">Ijazah terakhir</span>
					<select name="ijazah_terakhir" class="form-control form-elba input-sm">
						<?php foreach ($list_it->result() as $row){ ?>
							<option value="<?php echo $row->id_m_pendidikan; ?>"><?php echo  $row->pendidikan; ?></option>
						<?php }; ?>
					</select>
					</div>
					<br/>	
					<input type="text" id="tgl2" value="<?php echo date('d/m/Y');?>" name="tgl_reg" class="form-control form-elba input-sm clearable" placeholder="Tanggal Registrasi"/><br/>						
					<textarea name="alamat" class="form-control form-elba input-sm clearable" placeholder="Alamat tholabah"></textarea><br/><br/>
				</div>
				<div class="col-md-6">
					<input type="text" name="nama_ayah" class="form-control form-elba input-sm clearable" placeholder="Nama Ayah"/><br/>	
					<div class="input-group">
					<span class="input-group-addon group-addon-elba b-hijau-muda ">Pekerjaan Ayah</span>
					<select name="kerja_ayah" class="form-control form-elba input-sm">
						<?php foreach ($list_pk->result() as $row){ ?>
							<option value="<?php echo $row->id_m_pekerjaan; ?>"><?php echo  $row->pekerjaan; ?></option>
						<?php }; ?>
					</select>
					</div>
					<br/>
					<input type="tel" name="no_tlp_ayah" class="tel form-control form-elba input-sm bfh-phone clearable" data-format="+62 ddd-dddd-dddd" placeholder="No. Hp/Tlp Ayah"/><br/>
					<input type="text" name="nama_ibu" class="form-control form-elba input-sm clearable" placeholder="Nama Ibu"/><br/>	
					<div class="input-group">
					<span class="input-group-addon group-addon-elba b-hijau-muda ">Pekerjaan Ibu</span>
					<select name="kerja_ibu" class="form-control form-elba input-sm">
						<?php foreach ($list_pk->result() as $row){ ?>
							<option value="<?php echo $row->id_m_pekerjaan; ?>"><?php echo  $row->pekerjaan; ?></option>
						<?php }; ?>
					</select>
					</div>
					<br/>
					<input type="tel" name="no_tlp_ibu" class="tel form-control form-elba input-sm bfh-phone clearable" data-format="+62 ddd-dddd-dddd" placeholder="No. Hp/Tlp Ibu"/><br/>
					<textarea name="alamat_ortu" class="form-control form-elba input-sm clearable" placeholder="Alamat orang tua"></textarea><br/><br/>
				</div>	
			</div>

			<span id="loadingAdd" style="display:none;">Sedang memproses..</span>
			<span id="errorAdd" style="display:none;color:red;">Ma'af, gagal menambahkan data</span>
			<span class="pull-right"><button type="submit" class="btn btn-xs tmb-utama"> Simpan</button> <button class="btn tmb-kedua close-reveal-modal close-modal"> Batal</button></span>
			<?php
				echo form_close();
			?>
		</div>
	</div>

	<!-- Edit -->
	<div id="editModal" class="reveal-modal medium" data-reveal>
		<p class="p-modal">Edit Data Master Tholabah <?php echo $jp;?></p>
		<div class="isi-modal">			
			<div id="edit"></div>
		</div>
	</div>

	<!-- Delete -->
	<div id="delModal" class="reveal-modal tiny" data-reveal>
		<p class="p-modal"><span id="hpid" class='hpid var-modal' style="display:none;"></span>Yakin ingin menghapus <span class="nama var-modal"></span> dari daftar tholabah <?php echo $jp;?>?</p><br/><br/>
		<span id="loadingDel" style="display:none;">Sedang memproses..</span>
		<span id="errorDel" style="display:none;color:red;">Ma'af, gagal dihapus</span>
		<span class="pull-right"><button class="deleteUrl btn btn-xs tmb-utama" id="Hapus"> Yakin</button> <button class="btn tmb-kedua close-reveal-modal close-modal"> Tidak</button></span>
	</div>

	<!-- Detail -->
	<div id="detailModal" class="reveal-modal medium" data-reveal>
		<p class="p-modal">Detail Data Master Tholabah <?php echo $jp; ?></p>
		<div class="isi-modal">			
			<div id="detail"></div>
		</div>
	</div>
	
    <div class="col-lg-12">
        
        <div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Data Master Tholabah <?php echo $jp; ?>
				<button class="btn btn-sm tmb-tambah tmb-utama pull-right" data-reveal-id="addModal" data-reveal><i class="fa fa-plus"></i> Tambah</button>
			</div>
				
            <div class="panel-body">
				<div class="row">
					<div class="col-md-12">
						<div id="contentTholabah">
						<table class="table table-condensed">
						  <thead>
							<tr>
								<th>#</th>
								<th>NIT</th>
								<th>Nama Lengkap</th>
								<th>JK</th>
								<th>TTL</th>
								<th>Alamat</th>
								<th>Tgl. Daftar</th>
								<th></th>
							</tr>
						  </thead>
						  <tbody>
							<?php 
								if(count($list)>0){
									$i = 1; 
									foreach ($list as $row) {
							?>
							<tr class="hover">
								<td width="30"><?php echo $i++ ?></td>
								<td><?php echo $row->id_m_tholabah;?></td>
								<td><?php echo $row->nama_lengkap;?></td>								 
								<td><?php echo $row->jk;?></td> 
								<td><?php echo $row->tmp_lahir.', '.date("d/m/Y",strtotime($row->tgl_lahir));?></td>
								<td><?php echo substr($row->alamat,0,35);?>...</td>
								<td><?php echo date("d/m/Y",strtotime($row->tgl_reg));?></td> 
								<td class="text-right">											
									<a class="editorLink" data-reveal-id="delModal" data-reveal nama="<?php echo $row->nama_lengkap; ?>" hpid="<?php echo $row->id_m_tholabah;?>"><span class="glyphicon glyphicon-floppy-remove"></span> Hapus</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<a onclick="edit_tholabah('<?php echo $row->id_m_tholabah;?>','<?php echo $row->id_m_j_pendidikan;?>')" class="editorLink" data-reveal-id="editModal" data-reveal><span class="glyphicon glyphicon-edit"></span> Edit</a></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<a onclick="detail_tholabah('<?php echo $row->id_m_tholabah;?>')" class="editorLink" data-reveal-id="detailModal" data-reveal><span class="glyphicon glyphicon-file"></span> Detail</a>
								</td>
							</tr>
							<?php
									}
								}else{
							?>
							<tr>
								<td colspan="8"><center>Belum ada data master Tholabah <?php echo "$jp";?></center></td>
							</tr>
							<?php
								}
							?>
						  </tbody>
						</table>
						</div>
					</div>
				</div>
            </div>

        </div>

	</div>
	
</div>
<script>
// Auto Focus Input Form
$(document).on('opened', '[data-reveal]', function () {
	$('.clearable').first().focus();	
	$('.editFocus').focus();
	$(".editFocus").val($(".editFocus").val());	
});
$(document).on('closed', '[data-reveal]', function () {
	$('#errorAdd').hide();
	$('#errorDel').hide();
});	
// Datepicker
$('#tgl1').datepicker({
	format: "dd/mm/yyyy",
    language: "id",
    autoclose: true
});
$('#tgl2').datepicker({
	format: "dd/mm/yyyy",
    language: "id",
    autoclose: true,
    todayHighlight: true
});
// Save
$('#SaveTholabah').bind('submit', function(event) {
	var link = $(this).attr('action');
	var id_m_j_pendidikan = $("#id_m_j_pendidikan").val();
	$.ajax({
		url: link,
		type: "POST",
		data: $(this).serialize(),
		cache: false,
		beforeSend: function(){
			$('#errorAdd').hide();
			$('#loadingAdd').show();
		},          
		success: function() {
			var $container = $("#contentTholabah");
			$container.load("<?php echo site_url(); ?>m_tholabah/refresh/"+id_m_j_pendidikan);
			
			$('#loadingAdd').hide();
			$('#addModal').foundation('reveal', 'close');
		},
		error:function(){
			$('#loadingAdd').hide();
			$('#errorAdd').show();
		}
	});
	return false; // dont post it automatically
});
// Edit
function edit_tholabah(id_m_tholabah,id_m_j_pendidikan){
	$.ajax({
		type: "POST",
		url : "<?php echo site_url(); ?>m_tholabah/edit",
		data: "id_m_tholabah="+id_m_tholabah+"&id_m_j_pendidikan="+id_m_j_pendidikan,
		cache: false,
		success: function(response) {
			$('#edit').html(response);
		}
	});
	return false;
}
// Update
$(document).ajaxComplete(function(){
	$('#UpdateTholabah').bind('submit', function(event) {
		var link = $(this).attr('action');
		var id_m_j_pendidikan = $("#id_m_j_pendidikan").val();
		$.ajax({
			url: link,
			type: "POST",
			data: $(this).serialize(),
			cache: false,
			beforeSend: function(){
				$('#loadingUpdate').show();
			},          
			success: function() {
				var $container = $("#contentTholabah");
				$container.load("<?php echo site_url(); ?>m_tholabah/refresh/"+id_m_j_pendidikan);
				
				$('#loadingUpdate').hide();
				$('#editModal').foundation('reveal', 'close');
			},
			error:function(){
				$('#loadingUpdate').hide();
				$('#errorUpdate').show();
			}
		});
		return false; // dont post it automatically
	});
});
// Delete
$("#Hapus").on("click", function(){
	var id_m_tholabah = $("#hpid").text();
	var id_m_j_pendidikan = $("#id_m_j_pendidikan").val();
	$.ajax({
		type: "POST",
		data: "id_m_tholabah="+id_m_tholabah,
		url : "<?php echo site_url(); ?>m_tholabah/delete",				
		cache: false,
		beforeSend: function(){
			$('#loadingDel').show();
			$('#errorDel').hide();
		}, 
		success: function(){
			var $container = $("#contentTholabah");
			$container.load("<?php echo site_url(); ?>m_tholabah/refresh/"+id_m_j_pendidikan);
			
			$('#loadingDel').hide();
			$('#delModal').foundation('reveal', 'close');
		},
		error:function(){
			$('#loadingDel').hide();
			$('#errorDel').show();
		}
	});
	return false; 
});
// Detail
function detail_tholabah(id_m_tholabah){
	$.ajax({
		type: "POST",
		url : "<?php echo site_url(); ?>m_tholabah/detail",
		data: "id_m_tholabah="+id_m_tholabah,
		cache: false,
		success: function(response) {
			$('#detail').html(response);
		}
	});
	return false;
}
</script>